﻿@model IEnumerable<BenzInfo.Hockey.Grenadiers.Models.Background>

@{
    ViewBag.Title = BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Backgrounds;
}

<script type="text/javascript">

    $(document).ready(function () {

        $('#dialog_background').dialog({
            autoOpen: false,
            modal: true,
            draggable: false,
            resizable: false,
            width: 580,
            height: 'auto',
            buttons: [
                {
                    id: 'dialog_btn_save', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save',
                    click: function () {
                        $('form', this).submit();
                    }
                },
                {
                    id: 'dialog_btn_cancel', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Cancel',
                    click: function () {
                        $(this).dialog('close');
                    }
                }
            ]
        });

        $('#btn_add a').click(function () {
            var url = $(this).attr('href');
            var title = "@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.AddBackground";

            $('#dialog_btn_save span').html("@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save");

            $('#dialog_background').empty().load(url, function () {
                $('#dialog_background').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });

        $('#btn_edit a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit';

            $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save');

            $('#dialog_background').empty().load(url, function () {
                $('#dialog_background').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
    });

</script>

<h1>@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Backgrounds</h1>

<div id="dialog_background"></div>

    @if (ViewBag.CurrentUser != null)
    {
        <span id="btn_add">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.AddContest, "Add", "Backgrounds")</span>
    }
    
    <div style="text-align:center">

        @foreach (var item in Model)
        {
            <img src="@Url.Content("~/Utils/ImageHandler.ashx?src=backgrounds/" + item.FileName + "&maxwidth=600&maxheight=600")" alt="@((ViewBag.Lang == "fr") ? item.TitleFR : item.TitleEN)" title="@((ViewBag.Lang == "fr") ? item.TitleFR : item.TitleEN)"/>    
            <div>@((ViewBag.Lang == "fr") ? item.DescriptionFR : item.DescriptionEN)</div>
            
            if (ViewBag.CurrentUser != null)
            {
                <div><span id="btn_edit">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit, "Edit", new { id = @item.Id })</span>
                @Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete, "Delete", new { id = @item.Id }, new { onclick = "return confirm('Delete?')" })</div>              
            }
        }
    </div>